home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / asm_0_m.arj / INT.ASM < prev    next >
Assembly Source File  |  1985-01-25  |  3KB  |  131 lines

  1. ;Program to allow a program to be interupted at any time.
  2. ;assemble with bat file makeint, for tandy 2000
  3. ;Assemble with the DeSmet assembler using the make file makeint.bat
  4. ;Written by John N. White        last mod 1/25/85
  5. ;Note that some tricks were used to get a .com file with an interupt handler
  6. ;with the DeSmet package which normally produces .exe files.
  7. ;The timer interupt is intercepted and every 20 ticks this code is entered.
  8. ;If the cs:ip that was being executed is greater than the end of this
  9. ;program (which is terminate and stay resident) then a check is made on
  10. ;the keyboard status. If both shifts and the alt key are depresed then
  11. ;the program is terminated by putting an int 21h into its code and jumping to
  12. ;it. The address that was interupted will be displayed. If cs:ip is less
  13. ;than the end of this program then every tick will be checked instead of every
  14. ;20. The normal clock tick point is entered after this program finishes.
  15. DAT    equ    +100h            ;The DeSmet stuff assumes CS:0 is the
  16.                     ;start while in a .com file CS:100 is.
  17.  
  18. EXTRA    equ    0Ch            ;This is the extra bytes on the stack
  19.                     ;over what a simple interupt should
  20.                     ;have. Tandy 2000 = 1Ah, IBM = 0Ch
  21.                     ;(for dos 2.x)
  22.     cseg
  23.     jmp    init
  24.  
  25. check:
  26.     sti
  27.     push    bp
  28.     push    ax
  29.     push    cx
  30.     mov    bp,sp
  31.     mov    ax,[bp+6+EXTRA]        ;1A extera stuff on stack over raw int
  32.     mov    cl,4
  33.     shr    ax,cl
  34.     add    ax,[bp+8+EXTRA]
  35.     cmp    ax,cs:addr DAT
  36.     jbe    next_tick
  37.     cmp    ax,0C000h
  38.     jae    next_tick
  39.     mov    ah,2
  40.     int    16h
  41.     not    al
  42.     and    al,0Bh            ;see if both shifts and alt key pressed
  43.     jz    interupt_process
  44. next_tick:
  45.     pop    cx
  46.     pop    ax
  47.     pop    bp
  48. tick:    db    0EAh,0,0,0,0        ;will be set by init
  49.  
  50. interupt_process:
  51.     push    bx
  52.     push    si
  53. ;grab old cs:ip of doomed program
  54.     mov    bx,[bp+6+EXTRA]
  55.     push    bx
  56.     mov    bx,[bp+8+EXTRA]
  57. ;cause return to die instead of return to doomed program
  58.     mov    word [bp+6+EXTRA],offset die DAT
  59.     mov    word [bp+8+EXTRA],cs
  60.     mov    si,offset csnum DAT
  61.     mov    cx,4
  62. csloop:
  63.     call    cdigit
  64.     loop    csloop
  65.     mov    si,offset ipnum DAT
  66.     pop    bx
  67.     mov    cx,4
  68. iploop:
  69.     call    cdigit
  70.     loop    iploop
  71.     mov    si,offset dstring DAT    ;display dstring
  72. dloop:
  73.     mov    bl,0
  74.     mov    al,cs:[si]
  75.     inc    si
  76.     and    al,al
  77.     jz    done
  78.     mov    ah,14
  79.     int    10h            ;display char
  80.     jmp    dloop
  81.  
  82. done:
  83.     pop    si
  84.     pop    bx
  85.     jmp    next_tick
  86.  
  87. die:
  88.     mov    ax,4c01h        ;terminate current process
  89.     int    21h
  90.  
  91. ;convert lowest 4 bits in bx (>>=4) to hex digit at [si--]
  92. cdigit:
  93.     mov    al,bl
  94.     and    al,0Fh
  95.     shr    bx,1
  96.     shr    bx,1
  97.     shr    bx,1
  98.     shr    bx,1
  99.     cmp    al,9
  100.     jle    noadd
  101.     add    al,7
  102. noadd:    add    al,30h
  103.     mov    cs:byte [si],al
  104.     dec    si
  105.     ret
  106.  
  107. addr:    dw    0FFFFh            ;segment addr at end of this code
  108. dstring:db    0Dh,0Ah,'c','s','=',0,0,0
  109. csnum:    db    0,',',' ','i','p','=',0,0,0
  110. ipnum:    db    0,0Dh,0Ah,0
  111.  
  112. init:
  113.     mov    ax,351Ch        ;get tick interupt vector
  114.     int    21h
  115.     mov    ds:word tick+1 DAT,bx
  116.     mov    ds:word tick+3 DAT,es
  117.  
  118.     mov    ax,251Ch        ;set new tick vector
  119.     mov    dx,offset check DAT
  120.     int    21h
  121.  
  122.     mov    ax,cs
  123.     mov    dx,offset init+0Fh DAT
  124.     mov    cl,4
  125.     shr    dx,cl
  126.     add    ax,dx
  127.     mov    ds:addr DAT,ax
  128.     mov    ax,3100h        ;terminate and stay resident
  129.     int    21h
  130.     end
  131.